package com.wwu.config;

import com.wwu.service.IEmrDictService;
import com.wwu.service.IEmrInpService;
import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.annotation.Resource;
import javax.xml.ws.Endpoint;

/**
 * 类描述：发布WebService的配置类
 * @author 一蓑烟雨
 * @date 2021.09.29
 * @version 1.0.0
 **/
@Configuration
public class CxfConfig {
    @Resource
    private  ServiceAuthInterceptor serviceAuthInterceptor;
    @Resource
    private IEmrDictService emrDictService;
    @Resource
    private IEmrInpService emrInpService;


    /**
     * 设置项目服务访问地址
     * @return: org.springframework.boot.web.servlet.ServletRegistrationBean
     * @Author: 一蓑烟雨
     * @Date: 2022/3/17 0017 下午 12:13
     */
    @Bean
    public ServletRegistrationBean disServlet() {
        return new ServletRegistrationBean(new CXFServlet(), "/THWebService/*");
    }

    @Bean(name = Bus.DEFAULT_BUS_ID)
    public SpringBus springBus() {
        return new SpringBus();
    }

    /**
     * 电子病历基础字典服务
     * @return javax.xml.ws.Endpoint
     * @author 一蓑烟雨
     * @date 2022/3/16 0016 下午 12:08
     */
    @Bean
    public Endpoint emrDictServiceEndpoint() {
        EndpointImpl endpoint = new EndpointImpl(springBus(), emrDictService);
        //设置拦截器(进行鉴权)
        endpoint.getInInterceptors().add(serviceAuthInterceptor);
        endpoint.publish("/EmrDictService");
        return endpoint;
    }

    /**
     * 电子病历住院医疗业务数据服务
     * @return javax.xml.ws.Endpoint
     * @author 一蓑烟雨
     * @date 2022/3/16 0016 下午 12:08
     */
    @Bean
    public Endpoint emrInpServiceEndpoint() {
        EndpointImpl endpoint = new EndpointImpl(springBus(), emrInpService);
        //设置拦截器(进行鉴权)
        endpoint.getInInterceptors().add(serviceAuthInterceptor);
        endpoint.publish("/EmrInpService");
        return endpoint;
    }
}
